import pandas as pd
import re

pd.set_option('display.max_columns', None)
pd.set_option('display.width', None)
pd.set_option('display.max_colwidth', None)


def ends_with_time(text):
    """判断字符串是否以 yyyy-MM-dd hh:mm:ss 格式结尾"""
    pattern = r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'
    return bool(re.search(pattern, text))


if __name__ == '__main__':

    users = pd.read_csv('20251119users.csv')
    users = users[['user_account', 'org_full_name']]

    print(users.head())

    strArr = []
    i = 0
    skip_head = True
    str_one = ''
    with open('1.txt', 'r', encoding='utf-8') as f:
        read = f.read()
        split = read.split('\n')
        for e in split:
            if skip_head:
                skip_head = False
                continue
            if ends_with_time(e):
                str_one = str_one + "\n" + e
                strArr.append(str_one)
                str_one = ''
            else:
                str_one = str_one + "\n" + e

    data = [s.split('\t') for s in strArr]
    detail = pd.DataFrame(data, columns=['账号', '姓名', '问题', '答案', '记录时间'])
    detail['账号'] = detail['账号'].str.strip()
    print(detail.head())
    merge2 = pd.merge(detail, users, left_on="账号", right_on='user_account', how="left")
    print(merge2.head())
